package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.ShoppingDao;
import com.yazi.mxz.common.entity.beans.Shopping;
import com.yazi.mxz.common.entity.beans.ShoppingCart;
import com.yazi.mxz.common.entity.beans.StoreGoods;

import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("shoppingDao")
public class ShoppingDaoImpl extends BasicDao<Shopping> implements ShoppingDao {

	public ShoppingDaoImpl() {
		super(Shopping.class);
		
	}

	@Override
	public Criteria getExample(Shopping shopping, String searchWord) {
		Criteria c = super.getExample(shopping, searchWord);
		if (null != shopping) {
			// 购物车
			ShoppingCart cart = shopping.getShoppingCart();
			if (null != cart) {
				// 购物车ID
				if (null != cart.getCartId()) {
					c.add(Restrictions.eq("shoppingCart.cartId", cart.getCartId()));
				} else {
					// ...购物车其它条件
				}				
			}
			// 店铺商品
			StoreGoods storeGoods = shopping.getStoreGoods();
			if (null != storeGoods) {
				// 店铺商品ID
				if (null != storeGoods.getStoreGoodsId()) {
					c.add(Restrictions.eq("storeGoods.storeGoodsId", storeGoods.getStoreGoodsId()));
				} else {
					// ...店铺商品其它条件
				}				
			}
			// ...购物名物品其它关联对象条件
		}		
		// ...关键字searchWord查询条件
		return c;
	}
	
	@Override
	public void deleteByIds(long[] shoppingIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("shoppingIds", shoppingIds);
		executeUpdate("delByIdsHql", param);
	}

	@Override
	public void deleteByIds(long memberId, Long[] shoppingIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("memberId", memberId);
		param.put("shoppingIds", shoppingIds);
		executeUpdate("delByMemberIdshoppingIdsHql", param);
	}

}
